package StudyCode.summary.mycollection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ConvertArrayAndIteratorAsList {
	public static <E> List<E> asList(
			@SuppressWarnings("unchecked") final E... array) {
		List<E> list = new ArrayList<>(array.length);
		for (E element : array) {
			list.add(element);
		}
		return list;
	}

	public static <E> List<E> asList(final Iterator<? extends E> iterator) {
		List<E> list = new ArrayList<>();
		while (iterator.hasNext()) {
			list.add(iterator.next());
		}
		return list;
	}
}
